CLIP.Search.enc = function(val) {
	return val.replace(/\s/g, "+");
};

CLIP.Search.dec = function(val) {
	return val.replace(/\+/g, ' ');
};

CLIP.Clips.initPage = 1;
CLIP.Clips.currentPage = 1;
CLIP.Clips.pageSize = 35;

CLIP.Clips.searchUrl = function(keyword) {
	return 'http://xemphimso.com/tim-kiem/' + encodeURIComponent(keyword) + '/page-' + CLIP.Clips.currentPage + '.html';
};

CLIP.Clips.filterUrl = function() {
	return 'http://xemphimso.com/danh-sach/' + $('#types input:checked').val() + '/page-' + CLIP.Clips.currentPage + '.html?y=' + $('#years input:checked').val() + '&c='
			+ $('#cats input:checked').val();
};

CLIP.Clips.moreHtml = function(text) {
	var html = [];

	text = bum.util.parse(text, '<div class="tab-content videos fnRTContent" id="fnRTNew">', '<div class="pagination_list">');
	if (text == null) {
		return html;
	}
	$.each(text.split('<div class="content-items">'), function(i, clip) {
		if (i > 0) {
			++CLIP.Clips.moreCount;
			var code = bum.util.parse(clip, '<a href="', '"').replace('http://xemphimso.com/', '');
			var aTitle = bum.util.parse(clip, 'title="', '"').split(' - ');
			var title = aTitle[0];
			var originalTitle = aTitle[1] == undefined ? '' : aTitle[1];
			var img = bum.util.parse(clip, '<img src="', '"');

			html.push('<a class="item clip" href="#" code="', code, '"><div class="cw">');
			html.push('<img src="http://cdn.bum.vn/_.gif" style="background-image:url(', img, ');"/>');
			html.push('<div class="iw"><h4>', title, '</h4>');
			html.push('<h5>', originalTitle, '</h5></div>');
			html.push('</div></a>');
		}
	});

	return html;
};

CLIP.Info.infoUrl = function(code) {
	return 'http://xemphimso.com/' + code;
};

CLIP.Info.parseInfo = function(text) {
	text = bum.util.parse(text, '<div id="fnBodyContent" class="content">', '<!--End .content-items-->');
	if (text == null) {
		return null;
	}

	var poster = bum.util.parse(text, 'src="', '"');
	var title = bum.util.parse(text, '<h3>', '</h3>');
	var originalTitle = bum.util.parse(text, '</h3> ', ' <p>');

	var detail = '';
	var intro = bum.util.parse(text, '<div class="info_movie_detail"> ', '</div>').replace(/<\/p>/g, "\n");
	intro = $(intro).text().replace(/\n/g, '<br/>');
	intro = intro + bum.util.parse(text, '<div id="fnBiography" class="info-content clear_fix none" style="text-align: justify;">', '</div></div>');

	var chaps = null;

	// load eps
	var epsUrl = bum.util.parse(text, '<p> <a href="', '"').replace(/<[\/]{0,1}(iframe|a|font)[^><]*>/gi, "").replace(/style/g, 'styles').replace(
			/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '');
	if (epsUrl.startsWith('http://')) {
		bum.api.fetchUrl(epsUrl, CLIP.Chap.headers, CLIP.Info.getEps);
	} else {
		chaps = '<div><p>Phim đang cập nhật.<p></div>';
	}

	// return clip
	var clip = {
		poster : poster,
		title : title,
		originalTitle : originalTitle,
		detail : detail,
		chaps : chaps,
		intro : intro
	};

	return clip;
};

CLIP.Info.getEps = function(text) {
	if (text == null) {
		return;
	}

	var eps = [];
	$.each(text.split('<li class="server_item"'), function(i, item) {
		if (i > 0) {
			var sName = bum.util.parse(item, '<span class="name" style="line-height: 25px;">', '</span>');
			eps.push('<div><p><b>' + sName + '</b></p></div>');

			var steps = bum.util.parse(item, '<td class="listep"> ', '</td>');
			$.each(steps.split('&nbsp; '), function(i, step) {
				if (step != '') {
					var code = bum.util.parse(step, '<a href="', '"').replace('http://xemphimso.com/xem-phim/online/', '');
					var name = bum.util.parse(step, '<b>', '</b>');
					eps.push('<a href="' + code + '">' + name + '</a>');
				}
			});
		}
	});

	$('#chaps').html(eps.join(''));

	// clear
	eps = null;
};

CLIP.Chap.headers = [ 'Accept', 'text/plain, text/html', 'Host', 'xemphimso.com', 'Cache-Control', 'max-age=0', 'Connection', 'close', 'User-Agent',
		'Mozilla/5.0 (Linux; U; Android 2.2; en-us; DROID2 GLOBAL Build/S273) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' ].join('|');

CLIP.Chap.chapUrl = function(code) {
	return 'http://xemphimso.com/xem-phim/online/' + code;
};
// custome
CLIP.Chap.streamUrl = function(text) {
	return bum.util.parse(text, "<video width='100%' height='90%' src='", "'");
};